import _ from "lodash"

class ResultSet {
	status = 200
	message = ""
	data = null

	constructor() {
		this.setStatus(Array.from(arguments)[0])
		this.setMessage(Array.from(arguments)[1])
		this.setData(Array.from(arguments)[2])
	}

	setStatus(status) {
		this.status = _.isNumber(status) ? status : 200
	}

	setMessage(message) {
		this.message = _.isString(message) ? message : ""
	}

	setData(data) {
		this.data = !_.isNil(data) ? data : null
	}
}

ResultSet.success = function () {
	const resultSet = new ResultSet()
	resultSet.setStatus(200)
	resultSet.setMessage(Array.from(arguments)[0])
	resultSet.setData(Array.from(arguments)[1])
	return resultSet
}

ResultSet.error = function () {
	const resultSet = new ResultSet()
	resultSet.setStatus(500)
	resultSet.setMessage(Array.from(arguments)[0])
	resultSet.setData(Array.from(arguments)[1])
	return resultSet
}

export default ResultSet
